// 9.9
class RegularPolygon {
    // 私有数据字段
    private int n;      // 边数，默认3
    private double side; // 边长，默认1
    private double x;    // 中心点x坐标，默认0
    private double y;    // 中心点y坐标，默认0

    // 无参构造函数
    public RegularPolygon() {
        this.n = 3;
        this.side = 1;
        this.x = 0;
        this.y = 0;
    }

    // 构造函数：指定边数和边长，中心在(0,0)
    public RegularPolygon(int n, double side) {
        this.n = n;
        this.side = side;
        this.x = 0;
        this.y = 0;
    }

    // 构造函数：指定边数、边长和中心坐标
    public RegularPolygon(int n, double side, double x, double y) {
        this.n = n;
        this.side = side;
        this.x = x;
        this.y = y;
    }

    // 访问器方法
    public int getN() { return n; }
    public double getSide() { return side; }
    public double getX() { return x; }
    public double getY() { return y; }

    // 修改器方法
    public void setN(int n) { this.n = n; }
    public void setSide(double side) { this.side = side; }
    public void setX(double x) { this.x = x; }
    public void setY(double y) { this.y = y; }

    // 计算周长
    public double getPerimeter() {
        return n * side;
    }

    // 计算面积
    public double getArea() {
        return (n * side * side) / (4 * Math.tan(Math.PI / n));
    }

    // toString方法用于显示对象信息
    @Override
    public String toString() {
        return String.format("RegularPolygon[n=%d, side=%.2f, center=(%.2f, %.2f)]",
                n, side, x, y);
    }
}

// 公共类，类名与文件名一致
public class TestRegularPolygon {
    public static void main(String[] args) {
        // 创建三个RegularPolygon对象
        RegularPolygon polygon1 = new RegularPolygon(); // 无参构造函数
        RegularPolygon polygon2 = new RegularPolygon(6, 4); // 指定边数和边长
        RegularPolygon polygon3 = new RegularPolygon(10, 4, 5.6, 7.8); // 指定所有参数

        // 显示第一个多边形的信息
        System.out.println("多边形1: " + polygon1);
        System.out.printf("周长: %.2f\n", polygon1.getPerimeter());
        System.out.printf("面积: %.2f\n\n", polygon1.getArea());

        // 显示第二个多边形的信息
        System.out.println("多边形2: " + polygon2);
        System.out.printf("周长: %.2f\n", polygon2.getPerimeter());
        System.out.printf("面积: %.2f\n\n", polygon2.getArea());

        // 显示第三个多边形的信息
        System.out.println("多边形3: " + polygon3);
        System.out.printf("周长: %.2f\n", polygon3.getPerimeter());
        System.out.printf("面积: %.2f\n\n", polygon3.getArea());

        // 测试修改器方法
        System.out.println("=== 测试修改器方法 ===");
        polygon1.setN(5);
        polygon1.setSide(2.5);
        polygon1.setX(1.0);
        polygon1.setY(1.0);

        System.out.println("修改后的多边形1: " + polygon1);
        System.out.printf("新的周长: %.2f\n", polygon1.getPerimeter());
        System.out.printf("新的面积: %.2f\n", polygon1.getArea());
    }
}